<div class="content">
  <h1 mat-dialog-title class="title">添加设备</h1>
  <form  #assetForm="ngForm">
    <div mat-dialog-content class="asset-form">


    <mat-form-field appearance="standard">
      <mat-label>设备名称</mat-label>
      <input matInput required [(ngModel)]="asset.assetName" name="assetName">
      <mat-error *ngIf="messages.assetName">{{ messages.assetName }}</mat-error>
    </mat-form-field>

      <div style="display: inline-block; vertical-align: top; margin-top: 4px">
        <span class="imgLabel">设备图片</span>
        <br>
        <div class="uploadImg">
          <input type="file"  ng2FileSelect [uploader]="uploader" (change)="selectedFileOnChanged($event)" />
          <span>选择文件</span>
          <img *ngIf="asset.assetImgUrl1" [src]="asset.assetImgUrl1" alt="">
        </div>
        <!--<mat-error *ngIf="messages.assetName">{{ messages.assetName }}</mat-error>-->
      </div>

    <mat-form-field appearance="standard">
      <mat-label>设备品牌</mat-label>
      <input matInput required [(ngModel)]="asset.assetBrand" name="assetBrand" >
      <mat-error *ngIf="messages.assetBrand">{{ messages.assetBrand }}</mat-error>
    </mat-form-field>

      <!--<mat-form-field appearance="standard">-->
        <!--<mat-label>座位号</mat-label>-->
        <!--<input matInput required [(ngModel)]="asset.position" name="assetPosition" >-->
        <!--<mat-error *ngIf="messages.assetPosition">{{ messages.assetPosition }}</mat-error>-->
      <!--</mat-form-field>-->

    <mat-form-field appearance="standard">
      <mat-label>设备型号</mat-label>
      <input matInput [(ngModel)]="asset.assetVersion" name="assetVersion">
      <mat-error *ngIf="false"></mat-error>
    </mat-form-field>

      <mat-form-field>
        <mat-label>设备类型</mat-label>
        <mat-select placeholder="设备类型" [(value)]="asset.assetType">
          <mat-optgroup *ngFor="let assetType of assetTypes" [label]="assetType.GDZCLBMC">
            <mat-option *ngFor="let item of assetType.children" [value]="item.GDZCLB_DM">
              {{ item.GDZCLBMC }}
            </mat-option>
          </mat-optgroup>
        </mat-select>
      </mat-form-field>

    <mat-form-field *ngIf="isAdd" appearance="standard">
      <mat-label>数量</mat-label>
      <input matInput [(ngModel)]="asset.assetNum" name="assetNum" type="number" min="0">
      <mat-error *ngIf="false"></mat-error>
    </mat-form-field>

    <mat-form-field appearance="standard">
      <mat-label>设备状态</mat-label>
      <mat-select placeholder="设备状态" [(value)]="asset.assetStatus">
        <mat-option *ngFor="let status of assetStatus" [value]="status">
          {{StatusNameMap[status]}}
        </mat-option>
      </mat-select>
      <mat-error *ngIf="false"></mat-error>
    </mat-form-field>

      <mat-form-field appearance="standard">
        <mat-label>购买日期</mat-label>
        <input matInput [matDatepicker]="picker" placeholder="选择日期" [value]="asset.buyDateShow.value"
               (dateChange)="onSelectDate($event)">
        <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
        <mat-datepicker  #picker></mat-datepicker>
      </mat-form-field>

      <mat-form-field *ngIf="!isAdd"  appearance="standard">
        <mat-label>所属部门</mat-label>
        <mat-select  placeholder="所属部门" [(ngModel)]="asset.assetDepartmentId" (ngModelChange)="changeUser($event)" name="assetDepartmentId">
          <mat-option *ngFor="let department of departments" [value]="department.id">
            {{department.departName}}
          </mat-option>
        </mat-select>
        <mat-error *ngIf="false"></mat-error>
      </mat-form-field>

      <mat-form-field *ngIf="isAdd"  appearance="standard">
        <mat-label>所属部门</mat-label>
        <mat-select  placeholder="所属部门" [(ngModel)]="asset.assetDepartmentId" (ngModelChange)="changeUser($event)" name="assetDepartmentId">
          <mat-option  [value]="2">
            行政部门
          </mat-option>
        </mat-select>
        <mat-error *ngIf="false"></mat-error>
      </mat-form-field>

    <mat-form-field *ngIf="!isAdd" appearance="standard">
      <mat-label>负责人</mat-label>
      <mat-select placeholder="选择负责人" [(ngModel)]="asset.assetUserId" required name="assetUserId">
        <mat-option *ngFor="let departmentUser of departmentUsers" [value]="departmentUser.id">
          {{departmentUser.realName || departmentUser.username}}
        </mat-option>
      </mat-select>
      <mat-error *ngIf="false"></mat-error>
    </mat-form-field>

      <mat-form-field *ngIf="isAdd" appearance="standard">
        <mat-label>负责人</mat-label>
        <mat-select placeholder="选择负责人" [(ngModel)]="asset.assetUserId" required name="assetUserId">
          <mat-option *ngFor="let departmentUser of departmentUsers" [value]="departmentUser.id">
            {{departmentUser.realName || departmentUser.username}}
          </mat-option>
        </mat-select>
        <mat-error *ngIf="false"></mat-error>
      </mat-form-field>
</div>
  <div mat-dialog-actions class="buttons">
    <button mat-button (click)="onSubmit()">确认</button>
    <button mat-button [mat-dialog-close] cdkFocusInitial>取消</button>
  </div>
  </form>
</div>
